<template>
	<view>
	<uni-notice-bar speed="50" show-icon scrollable
							text="欢迎使用本公司设备,有问题请随时咨询客服13613814961(微信同号)" />
					<br/>
	
	<uni-grid :column="3" :highlight="true">
		
					<uni-grid-item @click="getWxJsCodeEdit('snsapi_base')">
						<view class="grid-item-box" >
							<uni-icons type="gear-filled" size="45" color="green"></uni-icons><br/>
							<text class="text" >设备配置</text>
						</view>
					</uni-grid-item>
					<uni-grid-item @click="getWeiXinJsCode('snsapi_base')">
						<view class="grid-item-box" >
							<uni-icons type="cart-filled" size="45" color="blue"></uni-icons><br/>
							<text class="text" >设备充值</text>
						</view>
					</uni-grid-item>
			<uni-grid-item @click="navigateTo('./fee')">
						<view class="grid-item-box" >
							<uni-icons type="compose" size="45" color="yellow"></uni-icons><br/>
							<text class="text" >资费标准</text>
						</view>
					</uni-grid-item>
				</uni-grid>
			<uni-grid :column="3" :highlight="true">
							<uni-grid-item @click="getConsume('snsapi_base')">
								<view class="grid-item-box">
									<uni-icons type="wallet" size="45" color="red"></uni-icons><br/>
									<text class="text" >消费记录</text>
								</view>
							</uni-grid-item>
							<uni-grid-item @click="getOrder('snsapi_base')">
								<view class="grid-item-box" >
									<uni-icons type="cart-filled" size="45" color="red"></uni-icons><br/>
									<text class="text" >充值记录</text>
								</view>
							</uni-grid-item>
					<uni-grid-item @click="navigateTo('./operate')">
								<view class="grid-item-box" >
									<uni-icons type="staff-filled" size="45" color="green"></uni-icons><br/>
									<text class="text" >操作指南</text>
								</view>
							</uni-grid-item>
						</uni-grid>
						<br/>
			<uni-section title="特别声明"
			subTitle="本产品属于通信设备，禁止用于非法用途，包括(滥发信息、恶意骚扰、非法改装等用于触犯法律法规的行为)。购买本产品时等同于同意接受本声明约束、等同同意签订相关责任书。如有违反，所有责任与本司无关。" type="line">
						
					</uni-section>		
		
		
		
		
		
		
		
		
			<uni-pay ref="pay" :adpid="adpid" return-url="/pages/order-detail/order-detail" logo="/static/logo.png" @success="onSuccess" @create="onCreate"></uni-pay>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			}
		},
		methods: {
			// 获取公众号code
			async getConsume(scope="snsapi_base") {
				let res = await this.$refs.pay.getProviderAppId({
					provider: "wxpay",
					provider_pay_type: "jsapi"
				});
				if (res.appid) {
					let appid = res.appid;
					//let redirect_uri = encodeURI(window.location.href.split("?")[0]);
					let redirect_uri=encodeURIComponent('https://iot.ixingyue.com/weixin/#/pages/pay/consume/')
					let url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&response_type=code&scope=${scope}&redirect_uri=${redirect_uri}&state=STATE#wechat_redirect`;
					window.location.href = url;
				}
			 
			}
			,
			// 获取公众号code
			async getOrder(scope="snsapi_base") {
				let res = await this.$refs.pay.getProviderAppId({
					provider: "wxpay",
					provider_pay_type: "jsapi"
				});
				if (res.appid) {
					let appid = res.appid;
					//let redirect_uri = encodeURI(window.location.href.split("?")[0]);
					let redirect_uri=encodeURIComponent('https://iot.ixingyue.com/weixin/#/pages/pay/order/')
					let url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&response_type=code&scope=${scope}&redirect_uri=${redirect_uri}&state=STATE#wechat_redirect`;
					window.location.href = url;
				}
			 
			}
			,
			// 获取公众号code
			async getWeiXinJsCode(scope="snsapi_base") {
				let res = await this.$refs.pay.getProviderAppId({
					provider: "wxpay",
					provider_pay_type: "jsapi"
				});
				if (res.appid) {
					let appid = res.appid;
					//let redirect_uri = encodeURI(window.location.href.split("?")[0]);
					let redirect_uri=encodeURIComponent('https://iot.ixingyue.com/weixin/#/pages/pay/pay/')
					let url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&response_type=code&scope=${scope}&redirect_uri=${redirect_uri}&state=STATE#wechat_redirect`;
					window.location.href = url;
				}
			 
			}
			,
			// 获取公众号code
			async getWxJsCodeEdit(scope="snsapi_base") {
				let res = await this.$refs.pay.getProviderAppId({
					provider: "wxpay",
					provider_pay_type: "jsapi"
				});
				if (res.appid) {
					let appid = res.appid;
					//let redirect_uri = encodeURI(window.location.href.split("?")[0]);
					let redirect_uri=encodeURIComponent('https://iot.ixingyue.com/weixin/#/pages/pay/editlist/')
					let url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&response_type=code&scope=${scope}&redirect_uri=${redirect_uri}&state=STATE#wechat_redirect`;
					window.location.href = url;
				}
			 
			},
			navigateTo(path) {
				uni.navigateTo({
					url:path
				})
			}
		}
	}
</script>

<style>
.grid-item-box{
	background-color: #fff;
	text-align: center;
    padding-top:28%;
    height: 100%;
}
</style>
